﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FriendsNearby.Services.Entities;

namespace FriendsNearby.Services
{
    public static class PeopleNearbyServiceExtensions
    {
        /// <summary>
        /// Report of <see cref="IPeopleNearbyService.GetPeopleNearby"/>
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="countFriendsNearby"></param>
        /// <param name="nearestDistance"></param>
        public static void GetPeopleNearbySummary(this IPeopleNearbyService service, string userId, out int countFriendsNearby, out double? nearestDistance)
        {
            IEnumerable<PersonNearby> personNearby = service.GetPeopleNearby(userId);
            countFriendsNearby = 0;
            nearestDistance = null;
            foreach (PersonNearby pn in personNearby)
            {
                nearestDistance = Math.Min(nearestDistance.GetValueOrDefault(double.MaxValue), pn.Distance.GetValueOrDefault(double.MaxValue));
                countFriendsNearby++;
            }
        }
    }
}
